package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.service.MenuService;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author wgq
 * @date 2019-10-19 22:48
 * 动态菜单栏展示
 */
@RestController
@RequestMapping("/menu")
public class MenuController {

    @Reference
    private MenuService menuService;

    /**
     * 动态获取菜单栏数据
     * @return
     */
    @RequestMapping("/findMenuList")
    public List<Map> findMenuList(){
        try {
            UserDetails user = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
            if(user != null){
                return menuService.findMenuList(user.getUsername());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
